<style scoped>
.wraper {
    padding: 0 20px 60px 20px;
}

.search-form {
    overflow: hidden;
}

.search {
    padding-bottom: 20px;
}

.search span {
    color: #68777c;
    font-weight: bold;
    padding-right: 18px;
}

.search button {
    background-color: #00a8f7;
    color: #fff;
    margin-left: 8px;
}

.top {
    margin-bottom: 20px;
    border-top: 1px dashed #cccccc;
}

.wraper .headline {
    position: relative;
    font-size: 12px;
    color: #303134;
    font-weight: bold;
    margin: 10px 0;
    line-height: 32px;
}

.wraper .add-agent {
    position: absolute;
    top: 0px;
    right: 30px;
    background-color: #348bf2;
    color: #fff;
}

.iconfont {
    font-size: 14px;
}

.red-font {
    color: #ff1f1f;
}

.fixed-bottom {
    padding-left: 20px;
    padding-right: 20px;
    height: 80px;
    line-height: normal !important;
    position: fixed;
    left: 210px;
    right: 0;
    bottom: 0;
    z-index: 999;
    text-align: center;
    background-color: rgb(255, 255, 255);
    box-shadow: 0px 0px 9px 0px rgba(0, 0, 0, 0.28);
}

.sidehide {
    left: 75px;
}

/* 表格样式 start*/

.pro-card {
    margin-bottom: 10px;
}

.pro-card-head {
    background-color: #e6e7eb;
    line-height: 38px;
    border: 1px solid #ddd;
}

.pro-card-title {
    font-size: 14px;
    color: #333;
    font-weight: bold;
    padding-left: 20px;
}

.pro-card-headr {
    padding-right: 10px;
    text-align: right;
}

.pro-card-content {
    clear: both;
}

.pro-paramname {
    text-align: center;
    background-color: #e6e7eb;
    font-size: 14px;
    color: #333;
    border-right: 1px solid #ddd;
}

.pro-paramvalue {
    padding-left: 10px;
    border-right: 1px solid #ddd;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.pro-card-contentrow {
    line-height: 40px;
    border-left: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
}

/* 表格样式  end */

/* 分页 start */

.page {
    margin: 0;
}

.ivu-page {
    padding-bottom: 150px;
}

/* 分页 end */

.receiptbox {
    padding: 10px;
    background-color: #edf2f6;
}

.receiptbox .ivu-input-group-append button {
    background-color: #19be6b;
    color: #fff;
}

.receiptbox .ivu-input-group {
    top: 0;
}

.receiptbox-upload {
    position: relative;
}

.receiptbox-upload-input {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    opacity: 0;
    cursor: pointer;
}

.receiptbox .ivu-tag {
    vertical-align: middle;
}

.renewal-box {
    margin-left: -16px;
    margin-right: -16px;
    padding: 16px;
    padding-bottom: 0;
    background-color: #cfebf9;
    overflow: hidden;
}

.renewal-pro {
    margin-left: -16px;
    margin-right: -16px;
    padding: 12px;
    height: 395px;
    overflow-y: auto;
}

.renewal-pro-title {
    padding-left: 15px;
    height: 50px;
    line-height: 50px;
    font-size: 16px;
    background-color: #edf2f6;
    margin-bottom: 10px;
}

.renewal-pro-title b {
    display: inline-block;
    margin-left: 20px;
}

.renewal-pro-checkbox {
    font-size: 14px;
    padding-left: 15px;
    border: 1px solid #edf2f6;
    height: 50px;
    line-height: 50px;
    margin-bottom: 10px;
}

.renewal-pro-price {
    color: #ff4848;
    font-size: 16px;
    padding-right: 15px;
}

.renewal-footer {
    margin: -12px -18px;
    padding: 12px 18px;
    background-color: #f2f2f2;
    overflow: hidden;
}

.renewal-footer-l {
    float: left;
}

.renewal-footer-r {
    float: right;
}

.renewal-total {
    padding-left: 15px;
    color: #ff3d3d;
    font-size: 25px;
}

.mod_table {
    margin-right: 22px;
    margin-top: 20px;
    height: 50px;
}
</style>
<style>
.a-link {
    color: #4074e1;
    text-decoration: underline;
    cursor: pointer;
}

.ivu-table-row-highlight .a-link {
    color: #fff;
}

.receiptbox .ivu-tag span.ivu-tag-text {
    max-width: 260px;
    overflow: hidden !important;
    display: inline-block;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.receiptbox .ivu-tag span.ivu-tag-dot-inner,
.receiptbox .ivu-tag i {
    vertical-align: middle;
}
</style>



<template>
    <div class="policy-manage">
        <product-title></product-title>
        <div class="wraper">
            <div class="pro-con-f common-box-body">
                <Row>
                    <h3 class="search-h3 huang">
                        快速搜索
                    </h3>
                    <Form :model="searchForm" class="search-form">
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <FormItem label="选择公司">
                            <!-- <Select v-model="searchForm.cid"  filterable  placeholder="选择保险公司" :transfer=true>  
                                        <Option v-for="(option, index) in comoptions" :value="option.cid" :key="index">{{option.name}}</Option>                               
                                    </Select> -->
                            <Select v-model="searchForm.policy_cid" multiple filterable placeholder="选择保险公司" :transfer=true>
                                <Option v-for="(option, index) in comoptions" :value="option.cid" :key="index">{{option.name}}</Option>
                            </Select>
                        </FormItem>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="投保单号">
                            <Input size="large" type="text" v-model="searchForm.insure_num" placeholder="请输入" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="保单号">
                            <Input size="large" type="text" v-model="searchForm.policy_num" placeholder="请输入" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="保单状态">
                            <Select v-model="searchForm.status" multiple transfer placeholder="请选择">
                                <Option value="1" key="预收件">预收件</Option>
                                <Option value="2" key="承保件">承保件</Option>
                                <Option value="3" key="契撤件">契撤件</Option>
                                <Option value="4" key="停效件">停效件</Option>
                                <Option value="5" key="失效件">失效件</Option>
                                <Option value="6" key="解约件">解约件</Option>
                                <Option value="7" key="终止件">终止件</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item>
                            <Select v-model="searchForm.type" transfer style="width:120px;float:left;">
                                <Option value="insure_date">投保时间</Option>
                                <Option value="underwrite_date">承保时间</Option>
                                <Option value="effect_date">生效日期</Option>
                                <Option value="receipt_date">回执时间</Option>
                                <Option value="visit_date">回访时间</Option>
                                <Option value="withdraw_date">撤单时间</Option>
                                <Option value="terminal_date">终止时间</Option>
                            </Select>
                            <DatePicker style="margin-left:120px;" @on-change="datachange($event,searchForm,'daterange')" v-model="searchForm.daterangetime" type="daterange" transfer placeholder="请选择"></DatePicker>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7" v-if="$accountType.filter_org">
                        <Form-item label="选择机构">
                            <!-- <Select ref="orgselect"  label-in-value :label="oname" filterable remote @on-change="orgchange($event)" :remote-method="oidremote" :loading="remoteloading" placeholder="请输入分支机构" v-model="searchForm.yun_org_mid" :transfer=true>
                                        <Option v-for="item in orglist" :value="item.value" :key="item.value">{{item.label}}</Option>                                                                                                                                       
                                    </Select> -->
                            <Select ref="orgselect" multiple filterable placeholder="请输入分支机构" v-model="searchForm.yun_org_mid" :transfer=true>
                                <Option v-for="item in orglist" :value="item.id" :key="item.id">{{item.shortn}}</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="业务员">
                            <Select v-model="searchForm.agent_name" label-in-value :label="aname" @on-change="agentchange($event)" transfer filterable remote :remote-method="remoteemployee" :loading="proloading" placeholder="请输入">
                                <Option v-for="(option, index) in employeelist" :value="option.label" :key="index">{{option.label}}</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="工号">
                            <Input size="large" clearable type="text" v-model="searchForm.job_code" placeholder="请输入" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="投保人">
                            <Input size="large" type="text" v-model="searchForm.appName" placeholder="请输入" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="被保人">
                            <Input size="large" type="text" v-model="searchForm.insured_name" placeholder="请输入" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="7">
                        <Form-item label="险种类别">
                            <Select v-model="searchForm.cate" multiple transfer placeholder="请选择">
                                <Option v-for="item in cate_list" :value="item.cate_name" :key="item.cate_name">{{item.cate_name}}</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="24" :md="24" :lg="$accountType.filter_org?10:17">
                        <Form-item style="padding-right:0px;">
                            <Button size="large" class="fr" type="primary" icon="ios-search" @click="search">搜索</Button>
                        </Form-item>
                        </Col>
                    </Form>
                    <Col span="24" class="table-action">
                    <Button type="warning" size="large" v-if="$isShow('policy/create')" class="fr" icon="plus" @click="createPloicy">新增</Button>
                    <div style="border-right: 1px solid #EDF2F6;padding-right: 15px;margin-right: 15px;" class="fr">
                        <Button type="info" size="large" class="fr" icon="icon iconfont icon-riqi" @click="computeList">批量计算标准/价值保费</Button>
                    </div>
                    <div v-if="$isShow('policy/batch_export')" style="border-right: 1px solid #EDF2F6;padding-right: 15px;margin-right: 15px;" class="fr">
                        <Button type="info" size="large" class="fr" icon="icon iconfont icon-daochu" @click="exportList">导出保单</Button>
                    </div>
                    <div v-if="$isShow('policy/import_policy')" style="padding-right: 15px;margin-right: 15px;" class="fr">
                        <Upload action="" :format="['xlsx']" name="file_input" :before-upload="handleUploadWl">
                            <Button type="info" size="large" class="fr" icon="icon iconfont icon-daoru">导入保单</Button>
                        </Upload>
                    </div>
                    <div style="border-right: 1px solid #EDF2F6;padding-right: 15px;margin-right: 15px;" class="fr">
                        <a href="https://test.kuaibao365.com/batch_export/download_employee_demo?service_type=3">
                            <Button type="info" size="large" class="fr" icon="icon iconfont icon-daochu">保单模板下载</Button>
                        </a>
                    </div>
                    </Col>
                </Row>
            </div>
            <div class="detail">
                <div class="clearfix">
                    <div class="table-theme">
                        <Table :loading="tableloading" height="670" ref="currentRowTable" @on-current-change="tableCurrentChange($event)" size="large" stripe highlight-row border :columns="columns1" :data="policylist" class=""></Table>
                    </div>
                </div>
            </div>
        </div>
        <div :class="slidetoggle?'fixed-bottom':'fixed-bottom sidehide' ">
            <Row class="pro-pagesize">
                <Col :sm="24" :md="12" :lg="14">
                <Button type="error" v-if="$isShow('policy/del')" :disabled="tableaction" @click="policyDel" size="large" class="fl mr10 ">删除</Button>
                <Button type="info" v-if="$isShow('policy/update')" :disabled="tableaction" @click="policyEdit" size="large" class="fl mr10">编辑</Button>
                <Button type="info" v-if="$isShow('policy/update')" :disabled="tableaction" @click="policyUnderwriteBtn" size="large" class="fl mr10">承保</Button>
                <Button type="info" v-if="$isShow('policy/update')" :disabled="tableaction" @click="policyeffectBtn" size="large" class="fl mr10">合同生效</Button>
                <Button type="info" v-if="$isShow('policy/update')" :disabled="tableaction" @click="policyReceiptBtn" size="large" class="fl mr10">回执</Button>
                <Button type="info" v-if="$isShow('policy/update')" :disabled="tableaction" @click="policyVisitBtn" size="large" class="fl mr10">回访</Button>
                <Button type="info" :disabled="tableaction" @click="policycompute" size="large" class="fl mr10">计算标准/价值保费</Button>
                </Col>
                <Col :sm="24" :md="12" :lg="10" class="tRight">
                <Page ref="pages" :current="currentpage" :total="listTotal" show-total show-sizer :page-size="pagesize" @on-change="pageChange" @on-page-size-change="pageSizeChange" placement="top" class="page"></Page>
                </Col>
            </Row>
        </div>
        <!-- 合同生效时间 -->
        <Modal v-model="effectModal" :mask-closable='closeable' width="600" title="合同生效" @on-ok="effectok" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">
                <Form :model="effect" ref="effect" :rules="effectValidate">
                    <Form-item label="合同生效时间" prop="effect_datetime">
                        <DatePicker type="date" v-model="effect.effect_datetime" @on-change="datachange($event,effect,'effect_date')" placeholder="选择合同生效时间"></DatePicker>
                    </Form-item>
                </Form>
                </Col>
            </Row>
        </Modal>
        <!-- 回访时间 -->
        <Modal v-model="revisitModal" :mask-closable='closeable' width="600" title="回访" @on-ok="visitInsure" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">
                <Form :model="revisitInsure" ref="revisit" :rules="ruleValidate">
                    <Form-item label="回访时间" prop="visit_datetime">
                        <DatePicker type="date" v-model="revisitInsure.visit_datetime" @on-change="datachange($event,revisitInsure,'visit_date')" placeholder="选择回访时间"></DatePicker>
                    </Form-item>
                </Form>
                </Col>
            </Row>
        </Modal>
        <!-- <Modal v-model="renewalModal" :mask-closable='closeable' width="600" title="续期管理"  :loading="loading">
            <div class="modal-body">            
                <Row>
                    <Col span="24">
                        <div class="import-left">
                            <div class="common-box-body">
                                <div class="import-search">
                                    <Form ref="formInline">
                                        <Form-item label="姓名">
                                            <Input placeholder="请输入姓名" v-model="searchemploy">
                                                <Button slot="append" @click="searchemp" type="primary" icon="icon iconfont icon-sousuo"></Button>
                                            </Input>
                                        </Form-item> 
                                    </Form>
                                </div> 
                                <div class="import-list">
                                    <Table :loading="tableloading" :show-header=false stripe height="415" :columns="columns" :data="emplist"></Table>
                                </div>                             
                            </div>
                        </div> 
                    </Col>
                </Row> 
            </div>                      
            <div slot="footer"></div>          
        </Modal>  -->
        <!-- 续期 -->
        <Modal v-model="renewalModal" :mask-closable='closeable' width="600" title="续期管理" :loading="loading">
            <Row class="common-box-body">
                <div class="renewal-box">
                    <Form :model="renewalInsure">
                        <Col span="8">
                        <Form-item>
                            <Select placeholder="保险年度" transfer>
                                <Option value="1">第一年</Option>
                                <Option value="2">第二年</Option>
                                <Option value="3">第三年</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col span="8">
                        <Form-item>
                            <Select placeholder="保险次数" transfer>
                                <Option value="1">第一年</Option>
                                <Option value="2">第二年</Option>
                                <Option value="3">第三年</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col span="8">
                        <Form-item>
                            <DatePicker transfer type="date" v-model="renewalInsure.visit_datetime" @on-change="datachange($event,renewalInsure,'visit_date')" placeholder="选择交费时间"></DatePicker>
                        </Form-item>
                        </Col>
                        <Col span="24">
                        <Form-item label="备注">
                            <Input placeholder=""></Input>
                        </Form-item>
                        </Col>
                    </Form>
                </div>
                <div class="renewal-pro">
                    <div class="renewal-pro-title">
                        被保人
                        <b>李月珍</b>
                    </div>
                    <CheckboxGroup>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                    </CheckboxGroup>
                    <div class="renewal-pro-title">
                        被保人
                        <b>李月珍</b>
                    </div>
                    <CheckboxGroup>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                    </CheckboxGroup>
                </div>
            </Row>
            <div slot="footer" class="renewal-footer">
                <div class="renewal-footer-l">总计
                    <span class="renewal-total">68165.48</span>
                </div>
                <div class="renewal-footer-r">
                    <Button type="primary" @click="policyEdit" size="large" class="fl mr10">确定</Button>
                    <Button type="ghost" @click="policyEdit" size="large" class="fl">取消</Button>
                </div>
            </div>
        </Modal>
        <!-- 回执 -->
        <Modal v-model="receiptModal" :mask-closable='closeable' title="回执" @on-ok="receiptok" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">
                <Form :model="receiptform" ref="receiptform" :rules="receiptValidate">
                    <Form-item label="回执时间" prop="receipt_datetime">
                        <DatePicker type="date" v-model="receiptform.receipt_datetime" @on-change="datachange($event,receiptform,'receipt_date')" placeholder="选择回执时间"></DatePicker>
                    </Form-item>
                    <div class="receiptbox">
                        <Form-item label="影像文档">
                            <Input type="text" disabled>
                            <div slot="append" class="receiptbox-upload">
                                <input type="file" accept="image/*" class="receiptbox-upload-input" @change="uploadChange($event)">
                                <Button icon="plus">上传附件</Button>
                            </div>
                            </Input>
                        </Form-item>
                        <div v-for="(item,index) in updatefilesname">
                            <Tag type="dot" @on-close="delfile(index)" @click.native="showupload(index)" closable color="blue">{{item}}</Tag>
                        </div>
                    </div>
                </Form>
                </Col>
            </Row>
        </Modal>
        <!-- 承保 -->
        <Modal v-model="underwriteModal" :mask-closable='closeable' width="600" title="承保" @on-ok="reInsure" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">
                <Form :model="underwrite" ref="underwrite" :rules="underwriteValidate">
                    <FormItem label="承保单号" prop="policy_num">
                        <Input v-model="underwrite.policy_num" placeholder="请输入承保单号"></Input>
                    </FormItem>
                    <Form-item label="承保时间" prop="underwrite_datetime">
                        <DatePicker type="date" v-model="underwrite.underwrite_datetime" @on-change="datachange($event,underwrite,'underwrite_date')" placeholder="选择承保时间"></DatePicker>
                    </Form-item>
                </Form>
                </Col>
            </Row>
        </Modal>
        <!--  计算标准/价值保费 -->
        <Modal v-model="computeModal" :mask-closable='closeable' width="600" title="计算标准/价值保费" @on-ok="computeOk" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">
                <Form :model="computeForm" ref="compute" :rules="computeValidate">
                    <Form-item label="险种名称">
                        <Select multiple filterable placeholder="请输入险种名字" v-model="computeForm.pro_mids" :transfer=true>
                            <Option v-for="item in prolist" :value="item.id" :key="item.id">{{item.name}}</Option>
                        </Select>
                    </Form-item>
                    <Form-item label="投保开始时间" prop="start_datetime">
                        <DatePicker type="date" v-model="computeForm.start_datetime" transfer @on-change="datachange($event,computeForm,'start_date')" placeholder="选择开始时间"></DatePicker>
                    </Form-item>
                    <Form-item label="投保结束时间" prop="end_datetime">
                        <DatePicker type="date" v-model="computeForm.end_datetime" transfer @on-change="datachange($event,computeForm,'end_date')" placeholder="选择结束时间"></DatePicker>
                    </Form-item>
                </Form>
                </Col>
            </Row>
            <div v-if="progressJia" style="padding:10px">
                <Progress :percent="percentJia"></Progress>
            </div>
        </Modal>
        <!--  导出报表 -->
        <Modal v-model="exportModal" :mask-closable='closeable' width="600" title="导出报表" @on-ok="exportOk(1)" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3" class="search-form">
                <Form :model="exportForm" :rules="exportValidate">
                    <Form-item label="计绩年月">
                        <DatePicker type="month" v-model="exportForm.settlement_datetime" clearable transfer @on-change="datachange($event,exportForm,'settlement_date')" placeholder="选择计绩年月"></DatePicker>
                    </Form-item>
                    <Form-item label="选择机构">
                        <Select multiple :disabled="!$accountType.filter_org?true:false" filterable placeholder="请输入分支机构" v-model="exportForm.yun_org_mid" :transfer=true>
                            <Option v-for="item in orglist" :value="item.id" :key="item.id">{{item.shortn}}</Option>
                        </Select>
                    </Form-item>
                    <Form-item label="选择保险公司">
                        <Select multiple filterable placeholder="选择保险公司" v-model="exportForm.policy_cid" :transfer=true>
                            <Option v-for="(option, index) in comoptions" :value="option.cid" :key="index">{{option.name}}</Option>
                        </Select>
                    </Form-item>
                    <Form-item label="保单状态">
                        <Select v-model="exportForm.status" transfer multiple placeholder="请选择">
                            <Option value="1">预收件</Option>
                            <Option value="2">承保件</Option>
                            <Option value="3">契撤件</Option>
                            <Option value="4">停效件</Option>
                            <Option value="5">失效件</Option>
                            <Option value="6">解约件</Option>
                            <Option value="7">终止件</Option>
                        </Select>
                    </Form-item>
                    <Form-item label="投保时间">
                        <!-- <DatePicker type="date" v-model="exportForm.start_datetime" transfer @on-change="datachange($event,exportForm,'start_date')"  placeholder="选择开始时间"></DatePicker> -->
                        <DatePicker @on-change="datachange($event,exportForm,'daterange')" v-model="exportForm.daterangetime" type="daterange" transfer placeholder="请选择"></DatePicker>
                    </Form-item>
                    <Form-item label="承保时间">
                        <!-- <DatePicker type="date" v-model="exportForm.start_datetime" transfer @on-change="datachange($event,exportForm,'start_date')"  placeholder="选择开始时间"></DatePicker> -->
                        <DatePicker @on-change="datachange($event,exportForm,'underwrite_date')" v-model="exportForm.underwrite_datetime" type="daterange" transfer placeholder="请选择"></DatePicker>
                    </Form-item>
                    <Form-item label="业务员">
                        <Input v-model="exportForm.agent_name" placeholder="请输入业务员"></Input>
                    </Form-item>
                    <!-- <Form-item label="投保结束时间">
                            <DatePicker type="date" v-model="exportForm.end_datetime" transfer @on-change="datachange($event,exportForm,'end_date')"  placeholder="选择结束时间"></DatePicker>
                        </Form-item> -->
                </Form>
                </Col>
            </Row>
        </Modal>
        <!-- 导入时弹出框 -->
        <!-- <Modal v-model="importModal" width="360" :closable="false" :mask-closable="false">
            <p slot="header" style="color:#fff;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>数据导入</span>
            </p>
            <div style="text-align:center">
                <p>{{statustxt}}</p>
                <Progress :percent="get_pre" :status="status"></Progress>
                <Scroll>
                    <p v-for="item in problem_list" :key="item">{{item}}</p>
                </Scroll>
            </div>
            <div slot="footer">
                <Button type="success" size="large" long :loading="modal_loading" @click="uploadbBtn">确定</Button>
            </div>
        </Modal> -->
        <!-- 导入exsl -->
        <Modal v-model="importModal" width="1300" :closable="false" :mask-closable="false">
            <p slot="header" style="color:#fff;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>数据导入展示</span>
            </p>
            <div style="text-align:center">
                <p>{{statustxt}}</p>
                <div>
                    <Row>
                        <Col>
                        <div class="">
                            <Table size="large" stripe border :columns="columns2" :data="policy_list" class="">
                            </Table>
                        </div>
                        </Col>
                    </Row>
                    <div :md="24" :lg="8" class="tRight mod_table">
                        <Page ref="pages2" :total="listTotal2" :page-size="pagesize2" @on-change="pageChange2" placement="top" class="page"></Page>
                    </div>
                </div>
            </div>
            <div class="err_msg" style="color:red">
                <span>{{err_msg}}</span>
                <span style="color:blue;">{{err_msg2}}</span>
                <span>{{err_msg3}}</span>
            </div>
            <div slot="footer" :md="24" :lg="8">
                <Button v-if="exportTag" type="primary" size="small" @click="exportBtn">导出错误信息</Button>
                <Button style="width:60px;" type="primary" size="small" @click="quxiao">取消导入</Button>
                <Button style="width:60px;" offset="20" class="tRight" v-if="modShow" type="success" size="small" long @click="uploadbBtnWl">确定导入</Button>
            </div>
        </Modal>

        <Modal v-model="cumputeStatusModal" width="360" :closable="false" :mask-closable="false">
            <p slot="header" style="color:#fff;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>计算标准/价值保费</span>
            </p>
            <div style="text-align:center">
                <p>{{cumputetxt}}</p>
                <Progress :percent="cumpute_get_pre" :status="cumputeStatus"></Progress>
            </div>
            <div slot="footer">
                <Button type="success" size="large" long :loading="modal_loading" @click="cumputeBtn">确定</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import productTitle from "../../components/productTitle";
import { parteGetByName } from "../../api/parter";
import { getStsTokenWrite, getStsTokenRead } from "../../api/common";
import { getByName } from "../../api/employee";
import { getListByName } from "../../api/yun_org";
import { getCateFirst, productGetAll } from "../../api/product";
import {
    getListUnderwrite,
    computePremium,
    batchExport,
    getPolicyIds,
    computFoldPremium,
    synchData,
    policyFileUpload,
    delPolicy,
    policyVisit,
    policyGetList,
    policyReceipt,
    policyGetReceipt,
    policyGetVisit,
    policyEffect,
    policyGetEffect,
    policyUnderwrite,
    policyGetUnderwrite,
    import_policy,
    import_policy2,
    add_policy,
    compute_premium_count,
    compute_fold_premium2
} from "../../api/policy";
import { formatTime } from "../../libs/time";
import { fileUpload } from "../../api/renewal";
import debounce from "lodash.debounce";
export default {
    data() {
        return {
            computedTotal: 0,
            computedList: [],
            computed_id: "",
            computedCount: 0,
            progressJia: false, //滚动条是否显示
            percentJia: 0,
            exportTag: false,
            exportUrl: "",
            exsl_url: "../../../static/xsl/保单导入模板 .xlsx",
            modShow: false,
            err_msg: "",
            err_msg2: "",
            err_msg3: "",
            formData: {},
            columns2: [
                {
                    title: "公司名称",
                    key: "cname",
                    align: "center"
                },
                {
                    title: "保单号",
                    key: "policy_num",
                    align: "center"
                },
                {
                    title: "保单状态",
                    key: "status",
                    align: "center",
                    render: (h, params) => {
                        switch (parseInt(params.row.status)) {
                            case 1:
                                return "预收件";
                                break;
                            case 2:
                                return "承保件";
                                break;
                            case 3:
                                return "契撤件";
                                break;
                            case 4:
                                return "停效件";
                                break;
                            case 5:
                                return "失效件";
                                break;
                            case 6:
                                return "解约件";
                                break;
                            case 7:
                                return "终止件";
                                break;
                        }
                    }
                },
                {
                    title: "险种名称",
                    key: "pro_name",
                    align: "center"
                },
                {
                    title: "险种类型",
                    key: "pro_is_main",
                    align: "center",
                    render: (h, params) => {
                        switch (parseInt(params.row.pro_is_main)) {
                            case 1:
                                return "主险";
                                break;
                            case 2:
                                return "附加险";
                                break;
                        }
                    }
                },
                {
                    title: "投保人姓名",
                    key: "applicant_name",
                    align: "center"
                },
                {
                    title: "被保人姓名",
                    key: "insured_name",
                    align: "center"
                },
                {
                    title: "营销员姓名",
                    key: "emp_name",
                    align: "center"
                },
                {
                    title: "信息提示",
                    key: "err",
                    align: "center",
                    render: (h, params) => {
                        return h(
                            "div",
                            {
                                style: {
                                    color: "red",
                                    fontSize: "12px"
                                }
                            },
                            params.row.err
                        );
                    }
                }
            ],
            page2: 1,
            pagesize2: 10,
            listTotal2: 0,

            demo: 0,
            prolist: [],
            statustxt: "数据导入中",
            cumputetxt: "计算中",
            status: "active",
            cumputeStatus: "active",
            errortag: 0,
            policy_list: [],
            problem_list: [],
            policy_count: 0,
            uplodeTag: 0,
            modal_loading: false,
            importModal: false,
            computeModal: false,
            cumputeStatusModal: false,
            computed_data: [],
            computed_count: 0,
            computed_tag: 0,
            computeForm: {
                start_datetime: formatTime(new Date(), "yyyy-MM-dd"),
                end_datetime: formatTime(new Date(), "yyyy-MM-dd"),
                start_date: formatTime(new Date(), "yyyy-MM-dd"),
                end_date: formatTime(new Date(), "yyyy-MM-dd"),
                pro_mids: []
            },
            exportModal: false,
            exportForm: {
                // start_datetime:formatTime(new Date(),'yyyy-MM-dd'),
                // end_datetime:formatTime(new Date(),'yyyy-MM-dd'),
                // start_date:formatTime(new Date(),'yyyy-MM-dd'),
                // end_date:formatTime(new Date(),'yyyy-MM-dd'),
                start_date: "",
                end_date: "",
                settlement_datetime: "",
                settlement_date: "",
                status: [],
                yun_org_mid: [],
                daterange: [],
                daterangetime: [],
                policy_cid: []
            },
            closeable: false,
            loading: true,
            page: 1,
            pagesize: 10,
            listTotal: 0,
            searchForm: {
                p: 1,
                pagesize: 10,
                policy_cid: [],
                yun_org_mid: [],
                appName: "",
                agent_name: "",
                underwite_year: "",
                underwite_yeartime: "",
                underwite_month: "",
                underwite_monthtime: "",
                daterangetime: [],
                type: "insure_date",
                status: [],
                insured_name: "",
                cate: []
            },
            orglist: [],
            remoteloading: false,
            cname: "",
            oname: "",
            aname: "",
            proloading: false,
            comoptions: [],
            employeelist: [],
            tableloading: true,
            tableaction: true,
            current: 0,
            currentpage: 1,
            effectModal: false,
            effect: {
                effect_datetime: "",
                effect_date: ""
            },
            revisitModal: false,
            revisitInsure: {
                visit_datetime: "",
                visit_date: "",
                policy_id: ""
            },
            receiptModal: false,
            receiptform: {
                receipt_datetime: "",
                receipt_date: "",
                policy_id: "",
                receipt_document: []
            },
            renewalModal: false,
            renewalInsure: {},
            underwriteModal: false,
            underwrite: {
                policy_num: "",
                underwrite_datetime: "",
                underwrite_date: "",
                policy_id: ""
            },
            cate_list: [],
            files: {},
            updatefilesname: [],
            currentRow: {},
            columns1: [
                {
                    title: "公司名称",
                    key: "cname",
                    align: "center",
                    width: 200
                },
                {
                    title: "投保单号",
                    key: "insure_num",
                    align: "center",
                    render: (h, params) => {
                        return h("div", {}, params.row.insure_num);
                    },
                    width: 200
                },
                {
                    title: "保单号",
                    key: "policy_num",
                    align: "center",
                    render: (h, params) => {
                        return h(
                            "div",
                            {
                                attrs: {
                                    class: "a-link"
                                }
                                // on: {
                                //     click: () => {
                                //         this.toDetail(params.row.policy_id);
                                //     }
                                // }
                            },
                            params.row.policy_num
                        );
                    },
                    width: 200
                },
                {
                    title: "保单状态",
                    key: "status_name",
                    align: "center",
                    // render:(h,params)=>{
                    //     switch (params.row.status)
                    //     {
                    //         case 1:
                    //             return "预收件"
                    //             break;
                    //         case 2:
                    //             return "承保件"
                    //             break;
                    //         case 3:
                    //             return "契撤件"
                    //             break;
                    //         case 4:
                    //             return "停效件"
                    //             break;
                    //         case 5:
                    //             return "失效件"
                    //             break;
                    //         case 6:
                    //             return "解约件"
                    //             break;
                    //         case 7:
                    //             return "终止件"
                    //             break;
                    //         default:
                    //             return "承保件"
                    //     }
                    // },
                    width: 100
                },
                {
                    title: "投保日期",
                    key: "insure_date",
                    align: "center",
                    width: 100
                },
                {
                    title: "承保日期",
                    key: "underwrite_date",
                    align: "center",
                    width: 100
                },
                {
                    title: "回执日期",
                    key: "receipt_date",
                    align: "center",
                    width: 100
                },
                {
                    title: "回访日期",
                    key: "visit_date",
                    align: "center",
                    width: 100
                },
                {
                    title: "机构",
                    key: "oname",
                    align: "center",
                    width: 200
                },
                {
                    title: "业务员",
                    key: "agent_name",
                    align: "center",
                    width: 100
                },
                {
                    title: "投保人",
                    key: "appName",
                    align: "center",
                    width: 100
                },
                {
                    title: "被保人",
                    key: "insured_name",
                    align: "center",
                    width: 100
                },
                {
                    title: "规模保费",
                    key: "premium",
                    align: "center",
                    width: 100
                },
                {
                    title: "险种",
                    key: "insurance_name",
                    align: "center",
                    width: 200
                },
                {
                    title: "年期",
                    key: "pay_period",
                    align: "center",
                    width: 100
                }
            ],
            policylist: [],
            effectValidate: {
                effect_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择合同生效时间",
                        trigger: "change"
                    }
                ]
            },
            underwriteValidate: {
                policy_num: [
                    {
                        required: true,
                        pattern: /^[0-9a-zA-Z]+$/,
                        message: "请正确填写保单号",
                        trigger: "change"
                    }
                ],
                underwrite_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择承保时间",
                        trigger: "change"
                    }
                ]
            },
            ruleValidate: {
                visit_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择回访时间",
                        trigger: "change"
                    }
                ]
            },
            receiptValidate: {
                receipt_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择回执时间",
                        trigger: "change"
                    }
                ]
            },
            computeValidate: {
                start_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择开始时间",
                        trigger: "change"
                    }
                ],
                end_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择结束时间",
                        trigger: "change"
                    }
                ]
            },
            exportValidate: {
                start_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择开始时间",
                        trigger: "change"
                    }
                ],
                end_datetime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择结束时间",
                        trigger: "change"
                    }
                ],
                settlement_datetime: [
                    {
                        required: true,
                        message: "请选择结束时间",
                        trigger: "blur"
                    }
                ]
            }
        };
    },
    components: {
        productTitle
    },
    computed: {
        slidetoggle() {
            return this.$store.state.sildeshow;
        },
        get_yun_id() {
            return this.$store.state.user.id;
        },
        get_pre() {
            // if(this.policy_list > 0){
            //     return parseInt(this.uplodeTag/this.policy_list)*100
            // }else{
            //     return 0
            // }
            //return this.policy_list > 0 ? (parseInt(this.uplodeTag/this.policy_list)*100) : 0
            return this.policy_count > 0
                ? parseInt(this.uplodeTag / this.policy_count * 100)
                : 0;
        },
        cumpute_get_pre() {
            return this.computed_count > 0
                ? parseInt(this.computed_tag / this.computed_count * 100)
                : 0;
        },
        daterange() {
            return this.exportForm.daterange;
        },
        percent() {
            return this.$store.state.socket.compute_premium;
        }
    },
    watch: {
        daterange(newValue, oldValue) {
            if (newValue.length > 0) {
                this.exportForm.start_date = newValue[0] ? newValue[0] : "";
                this.exportForm.end_date = newValue[1] ? newValue[1] : "";
            } else {
                this.exportForm.start_date = "";
                this.exportForm.end_date = "";
            }
        }
        // percent(newValue){
        //     console.log(newValue,'....')
        //     //this.demo = newValue
        // }
    },
    channel: "progress." + sessionStorage.getItem("id"),
    mounted() {
        this.getList();
        this.orglistinit();
        this.cominit();
        this.getCate();

        console.log(this.$store);
        console.log(this.$echo);
        let _id = "progress." + sessionStorage.getItem("id");
        this.$echo.channel(_id).listen("ProgreeNotice", payload => {
            console.log(payload);
            //this.$store.dispatch('changesocket', payload);
            this.$store.commit("CHANGE_SOCKET", payload);
            // this.$nextTick(() => {
            //     setTimeout(() => {
            //         this.demo = payload.progress
            //     },200)
            // })
        });
        // let date=new Date().toLocaleDateString().split('/');
        // if(date[1]=="1"){
        //     this.exportForm.settlement_datetime = (date[0]*1-1)+"-12" ;
        //     this.exportForm.settlement_date= (date[0]*1-1)+"-12";
        // }else{
        //     this.exportForm.settlement_datetime = (date[0]+"-0"+(date[1]*1-1));
        //     this.exportForm.settlement_date = (date[0]+"-0"+(date[1]*1-1));
        // }
    },
    methods: {
        //导入保单导出错误信息
        exportBtn() {
            var iframe = document.createElement("iframe");
            iframe.style.display = "none";
            iframe.src = this.exportUrl;
            document.body.appendChild(iframe);
        },
        // WL 修改导入exsl
        quxiao() {
            this.importModal = false;
            console.log(this.policy_list, "AA", this.listTotal2);
            this.policy_list = [];
            this.formData.p = 1;
            this.formData.uniqid = "";
            this.listTotal2 = 0;
            this.page2 = 1;
            this.$refs["pages2"].currentPage = 1;
            this.modShow = false;

            console.log(this.policy_list, "BBBB", this.listTotal2);
        },
        get_file_list() {
            new Promise((resolve, reject) => {
                console.log(this.formData, "////");
                import_policy2(this.formData)
                    .then(response => {
                        if (response.data.err == 0) {
                            this.policy_list = response.data.list;
                            this.listTotal2 = response.data.total;
                        } else {
                            this.$Message.error("上传失败！");
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        // 页码改变
        pageChange2(page) {
            var clie = Math.ceil(this.listTotal2 / 10);
            if (page != clie) {
                this.modShow = false;
            } else {
                this.modShow = true;
            }
            this.page2 = page;
            this.formData.p = this.page2;
            console.log(this.formData.uniqid, "xxx", this.formData);
            this.get_file_list();
        },
        // 打开弹窗
        uploadbBtnWl() {
            this.sendDatawl(this.policy_list);
            this.$refs["pages2"].currentPage = 1;
            this.modShow = false;
            this.getList();
        },
        // 导入员工数据
        //上传之前
        handleUploadWl(file) {
            this.importModal = true;
            new Promise((resolve, reject) => {
                let param = new FormData();
                param.append("file", file);
                console.log(file);
                import_policy(param)
                    .then(response => {
                        if (response.data.err == 0) {
                            this.policy_list = response.data.list;
                            this.listTotal2 = response.data.total;
                            if (this.listTotal2 < 10) {
                                this.modShow = true;
                            }
                            this.formData.uniqid = response.data.uniqid;
                            this.importModal = true;
                            if (response.data.url) {
                                this.exportTag = true;
                                this.exportUrl = response.data.url;
                            } else {
                                this.exportTag = false;
                                this.exportUrl = "";
                            }
                        } else {
                            this.$Message.error("上传失败！");
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
            return false;
        },
        sendDatawl(obj) {
            console.log(obj, "...obj");
            new Promise((resolve, reject) => {
                let _params = {
                    uniqid: this.formData.uniqid
                };
                add_policy(_params)
                    .then(response => {
                        if (response.data.err == 0) {
                            this.importModal = false;
                            this.$Message.success("导入成功");
                        } else {
                            this.$Message.error(response.data.msg);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },

        policycompute() {
            this.$Modal.confirm({
                title: "提示",
                content: "是否要重新计算该保单标准/价值/年度标准保费?",
                onOk: () => {
                    let _params = {
                        policy_id: this.currentRow.policy_id
                    };
                    new Promise((resolve, reject) => {
                        computFoldPremium(_params)
                            .then(response => {
                                if (response.data.err == 0) {
                                    this.$Message.success(response.data.info);
                                } else {
                                    this.$Message.error(response.data.info);
                                }
                                resolve();
                            })
                            .catch(error => {
                                reject(error);
                                this.$Message.error("操作失败");
                            });
                    });
                }
            });
        },
        getProList() {
            new Promise((resolve, reject) => {
                productGetAll()
                    .then(response => {
                        if (response.data.err == 0) {
                            this.prolist = response.data.data;
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        cumputeBtn() {
            this.cumputeStatusModal = false;
            this.cumputeStatus = "active";
            this.computed_tag = 0;
            this.cumputetxt = "计算中";
        },
        computeList() {
            this.computeModal = true;
            if (this.prolist.length == 0) {
                this.getProList();
            }
        },
        computeOk() {
            // this.$refs["compute"].validate(valid => {
            //     if (valid) {
            //         new Promise((resolve, reject) => {
            //             computePremium(this.computeForm)
            //                 .then(response => {
            //                     if (response.data.err == 0) {
            //                         this.computeModal = false;
            //                         this.$Message.success("计算完成！");
            //                         resolve();
            //                     } else {
            //                         this.$Message.error(response.data.info);
            //                     }
            //                     setTimeout(() => {
            //                         this.loading = false;
            //                         this.$nextTick(() => {
            //                             this.loading = true;
            //                         });
            //                     }, 2000);
            //                 })
            //                 .catch(error => {
            //                     reject(error);
            //                 });
            //         });
            //     } else {
            //         setTimeout(() => {
            //             this.loading = false;
            //             this.$nextTick(() => {
            //                 this.loading = true;
            //             });
            //         }, 2000);
            //     }
            // });
            // WL  2018-7-30时总提出修改需求
            this.$refs["compute"].validate(valid => {
                if (valid) {
                    new Promise((resolve, reject) => {
                        compute_premium_count(this.computeForm)
                            .then(response => {
                                if (response.data.err == 0) {
                                    this.computedList = response.data.data.list;
                                    this.computedTotal = response.data.data.total;
                                    if (this.computedTotal > 0) {
                                        this.loading = true;
                                        this.progressJia = true;
                                        this.syncJia(this.computedTotal);
                                    } else {
                                        this.progressJia = false;
                                        this.$Message.error("没有人员可以计算");
                                    }
                                    resolve();
                                } else {
                                    this.$Message.error(response.data.info);
                                }
                                // setTimeout(() => {
                                //     this.loading = false;
                                //     this.$nextTick(() => {
                                //         this.loading = true;
                                //     });
                                // }, 2000);
                            })
                            .catch(error => {
                                reject(error);
                            });
                    });
                } else {
                    setTimeout(() => {
                        this.loading = false;
                        this.$nextTick(() => {
                            this.loading = true;
                        });
                    }, 2000);
                }
            });
        },
        syncJia(_userlistasc) {
                if (this.computedCount > _userlistasc) {
                    this.loading = false;
                    this.computeModal = false;
                    this.$Message.success("计算完成！");
                    this.progressJia = false;
                    return;
                }
                var _params = {
                    policy_id:this.computedList[this.computedCount]
                }
                new Promise((resolve, reject) => {
                    compute_fold_premium2(_params).then(response => {
                        this.percentJia = parseInt((this.computedCount * 100 / _userlistasc).toFixed(1))
                        this.computedCount++
                        this.syncJia(_userlistasc)
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
        computefee() {
            let _length = this.computed_count;
            if (this.computed_tag != _length) {
                this.computeDo(this.computed_data[this.computed_tag]);
            } else {
                this.cumputetxt = "计算完成。";
                this.modal_loading = false;
            }
        },
        computeDo(policy_id) {
            let _params = {
                policy_id: policy_id
            };
            new Promise((resolve, reject) => {
                computFoldPremium(_params)
                    .then(response => {
                        this.computed_tag++;
                        this.computefee();
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        // uploadbBtn() {
        //     this.importModal = false
        //     this.uplodeTag = 0
        //     this.problem_list = []
        //     this.status = 'active'
        //     this.statustxt = '数据导入中'
        //     this.errortag = 0
        // },
        // 上传之前
        handleUpload(file) {
            this.importModal = true;
            new Promise((resolve, reject) => {
                let param = new FormData();
                param.append("file", file);

                console.log(file);

                this.modal_loading = true;
                policyFileUpload(param)
                    .then(response => {
                        console.log(response.data, "FileUpload接口返回什么");
                        if (response.data.err == 0) {
                            console.log(
                                response.data.data,
                                "response.data.dataAAA"
                            );
                            this.policy_list = response.data.data;
                            let _length = this.policy_list.length;
                            this.policy_count = _length;
                            if (_length > 0) {
                                this.sendData();
                            }
                        } else {
                            this.$Message.error("上传失败！");
                            this.modal_loading = false;
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
            return false;
        },
        sendData() {
            if (this.uplodeTag != this.policy_count) {
                console.log(this.uplodeTag, "...", this.policy_count);
                this.updateData(this.policy_list[this.uplodeTag]);
            } else {
                return false;
            }
        },
        updateData(obj) {
            console.log(obj, "..................给什么啊");
            new Promise((resolve, reject) => {
                let _params = {
                    insure_num: obj.insure_num,
                    yid: obj.yid,
                    token: obj.token
                };
                synchData(_params)
                    .then(response => {
                        console.log(response, "synchData有什么用啊");
                        if (response.data.err == 0) {
                        } else {
                            this.errortag++;
                            this.problem_list.push(response.data.info);
                        }
                        this.uplodeTag++;
                        if (this.uplodeTag == this.policy_count) {
                            this.statustxt =
                                "导入完成。成功：" +
                                (this.policy_count - this.errortag) +
                                "条，失败：" +
                                this.errortag +
                                "条";
                            this.modal_loading = false;
                        } else {
                            this.sendData();
                        }
                        resolve();
                    })
                    .catch(error => {
                        this.modal_loading = false;
                        this.status = "wrong";
                        this.statustxt = "导入失败";
                        reject(error);
                    });
            });
        },
        getCate() {
            new Promise((resolve, reject) => {
                getCateFirst().then(response => {
                    console.log(response);
                    if (response.data.err == 0) {
                        this.cate_list = response.data.data;
                    }
                });
            });
        },
        exportList() {
            this.exportModal = true;
        },
        getDayNum() {},
        exportOk(val) {
            //打开一个不被拦截的新窗口
            //var adPopup = window.open('about:blank', '_blank','width='+window.screen.width+',height='+window.screen.height+', ...');
            //var newWindow = window.open();
            let _tag = 0;
            // let _obj = Object.keys(this.exportForm)
            // console.log(_obj)
            let _opt = [
                "settlement_datetime",
                "settlement_date",
                "underwrite_datetime",
                "yun_org_mid",
                "policy_cid",
                "status",
                "agent_name",
                "start_date",
                "end_date"
            ];
            for (var i in _opt) {
                if (
                    this.exportForm[_opt[i]] &&
                    this.exportForm[_opt[i]].length &&
                    this.exportForm[_opt[i]][0]
                ) {
                    console.log(this.exportForm[_opt[i]]);
                    _tag++;
                    break;
                }
            }
            if (_tag == 0) {
                this.$Message.error("请添加筛选条件！");
                setTimeout(() => {
                    this.loading = false;
                    this.$nextTick(() => {
                        this.loading = true;
                    });
                }, 1000);
                return false;
            }
            if (this.exportForm.start_date && this.exportForm.end_date) {
                let _start = new Date(this.exportForm.start_date).getTime();
                let _end = new Date(this.exportForm.end_date).getTime();
                let _day = Math.floor((_end - _start) / (24 * 3600 * 1000));
                if (_day > 366) {
                    this.$Message.error("投保时间跨度不可以超过一年！");
                    setTimeout(() => {
                        this.loading = false;
                        this.$nextTick(() => {
                            this.loading = true;
                        });
                    }, 1000);
                    return false;
                }
            }
            if (
                this.exportForm.underwrite_datetime[0] &&
                this.exportForm.underwrite_datetime[1]
            ) {
                let _start = new Date(
                    this.exportForm.underwrite_datetime[0]
                ).getTime();
                let _end = new Date(
                    this.exportForm.underwrite_datetime[1]
                ).getTime();
                let _day = Math.floor((_end - _start) / (24 * 3600 * 1000));
                if (_day > 366) {
                    this.$Message.error("承保时间跨度不可以超过一年！");
                    setTimeout(() => {
                        this.loading = false;
                        this.$nextTick(() => {
                            this.loading = true;
                        });
                    }, 1000);
                    return false;
                }
            }

            this.exportForm.count = val;
            new Promise((resolve, reject) => {
                batchExport(this.exportForm)
                    .then(response => {
                        if (response.data.err == 0) {
                            //             adPopup.blur();
                            // 　　　　    adPopup.opener.focus();
                            // 　　　　　　adPopup.location = response.data.data.url;
                            // var newWindow = window.open();
                            // newWindow.location.href = response.data.data.url;

                            //window.open(response.data.data.url)

                            if (response.data.data.url) {
                                var iframe = document.createElement("iframe");
                                iframe.style.display = "none";
                                iframe.src = response.data.data.url;
                                document.body.appendChild(iframe);
                            } else {
                                this.exportOk(val + 1);
                                this.$Spin.show({
                                    render: h => {
                                        return h("div", [
                                            h("Icon", {
                                                class: "demo-spin-icon-load",
                                                props: {
                                                    type: "load-c",
                                                    size: 18
                                                }
                                            }),
                                            h("div", "Loading")
                                        ]);
                                    }
                                });
                            }
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        setTimeout(() => {
                            this.loading = false;
                            this.$nextTick(() => {
                                this.loading = true;
                            });
                        }, 2000);
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                        setTimeout(() => {
                            this.loading = false;
                            this.$nextTick(() => {
                                this.loading = true;
                            });
                        }, 2000);
                    });
            });

            // var _exprot_arry = '';
            // if(this.exportForm.yun_org_mid.length > 0){
            //     _exprot_arry = this.exportForm.yun_org_mid.join("_")
            // }
            // console.log(_exprot_arry)
            // window.open('http://192.168.0.88:8080/batch_export/export_policy?settlement_date='+this.exportForm.settlement_date+'&&status='+this.exportForm.status+'&&start_date='+this.exportForm.start_date+'&end_date='+this.exportForm.end_date+'&yun_id='+this.get_yun_id+'&yun_org_mid='+_exprot_arry)

            //window.open('http://192.168.0.88:8080/batch_export/export_policy?start_date='+this.exportForm.start_date+'&end_date='+this.exportForm.end_date+'&yun_id='+this.get_yun_id+'&yun_org_mid='+_exprot_arry)
        },
        //时间转换
        datachange(date, obj, param) {
            obj[param] = date;
        },
        orglistinit() {
            new Promise((resolve, reject) => {
                let _params = {
                    name: ""
                };
                getListByName(_params)
                    .then(response => {
                        console.log(response.data);
                        if (response.data.err == 0) {
                            this.orglist = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        cominit() {
            new Promise((resolve, reject) => {
                let _params = {
                    name: ""
                };
                parteGetByName(_params)
                    .then(response => {
                        console.log(response.data);
                        if (response.data.err == 0) {
                            this.comoptions = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        //机构改变
        // orgchange(value){
        //     console.log(this.$refs)
        //     console.log(value)
        //     this.oname = value.label
        // },
        // oidremote(query){
        //     if (query !== '') {
        //         if(query == this.oname){
        //             this.searchForm.yun_org_mid = ''
        //             return
        //         }
        //         this.remoteloading = true;
        //         this.remoteorg(query)
        //     } else {
        //         this.orglistinit();
        //     }
        // },
        // remoteorg:debounce(function (query) {

        //     new Promise((resolve, reject) => {
        //     let _params = {
        //         name:query
        //     }
        //     getListByName(_params).then(response => {
        //             console.log(response.data)
        //             if (response.data.err == 0) {
        //                 this.remoteloading = false;
        //                 const list = response.data.data.map(item => {
        //                 return {
        //                         value: item.id,
        //                         label: item.shortn
        //                     };
        //                 });
        //                 this.orglist = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);
        //             } else {
        //                 this.$Message.error(response.data.info);
        //             }
        //             resolve();
        //         }).catch(error => {
        //             reject(error);
        //         });
        //     });
        // },300),
        //删除回执资料
        delfile(index) {
            console.log(index);
            this.updatefilesname.splice(index, 1);
            this.receiptform.receipt_document.splice(index, 1);
        },
        //上传回执资料
        uploadChange(e) {
            console.log(e);
            this.files = {};
            var files = e.target.files[0];
            this.files = files;
            if (!/\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG)$/.test(e.target.value)) {
                this.$Message.error(
                    "图片类型必须是.gif,jpeg,jpg,png,bmp中的一种"
                );
                return false;
            }
            new Promise((resolve, reject) => {
                getStsTokenWrite()
                    .then(response => {
                        if (response.data.err == 0) {
                            let r = new FileReader();
                            let sts = response.data.data.Credentials;
                            var client = new OSS.Wrapper({
                                region: "oss-cn-hangzhou",
                                accessKeyId: sts.AccessKeyId,
                                accessKeySecret: sts.AccessKeySecret,
                                stsToken: sts.SecurityToken,
                                bucket: "kuaibao-imgs",
                                secure: true
                            });
                            if (this.files) {
                                let name = this.files.name;
                                let file = this.files;
                                var imageType = /^image\//;
                                //是否是图片
                                if (!imageType.test(file.type)) {
                                    this.$Message.error("请选择图片！");
                                    return;
                                }
                                client
                                    .multipartUpload(name, file, {})
                                    .then(results => {
                                        console.log(results);
                                        if (this.files.size > 102400) {
                                            console.log("100");
                                            this.updatefilesname.push(
                                                results.name
                                            );
                                            let url = results.res.requestUrls[0].split(
                                                "?"
                                            )[0];
                                            this.receiptform.receipt_document.push(
                                                url
                                            );
                                        } else {
                                            console.log("<100");
                                            if (results.name) {
                                                this.updatefilesname.push(
                                                    results.name
                                                );
                                                this.receiptform.receipt_document.push(
                                                    results.url
                                                );
                                            }
                                        }
                                    });
                            }
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        //获取回执信息
        getreceipt() {
            let params = {
                policy_id: this.currentRow.policy_id
            };
            new Promise((resolve, reject) => {
                policyGetReceipt(params)
                    .then(response => {
                        if (response.data.err == 0) {
                            if (response.data.data.receipt_date) {
                                this.receiptform.receipt_datetime =
                                    response.data.data.receipt_date;
                                this.receiptform.receipt_date =
                                    response.data.data.receipt_date;
                                this.receiptform.receipt_document = response
                                    .data.data.receipt_document
                                    ? response.data.data.receipt_document
                                    : [];
                                if (
                                    response.data.data.receipt_document &&
                                    this.receiptform.receipt_document.length > 0
                                ) {
                                    this.updatefilesname = response.data.data.receipt_document.map(
                                        function(item) {
                                            let arry = item.split("/");
                                            return decodeURI(
                                                arry[arry.length - 1]
                                            );
                                        }
                                    );
                                } else {
                                }
                            }
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        //获取回访信息
        getvisit() {
            let params = {
                policy_id: this.currentRow.policy_id
            };
            new Promise((resolve, reject) => {
                policyGetVisit(params)
                    .then(response => {
                        if (response.data.err == 0) {
                            if (response.data.data.visit_date) {
                                this.revisitInsure.visit_datetime =
                                    response.data.data.visit_date;
                                this.revisitInsure.visit_date =
                                    response.data.data.visit_date;
                            }
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        //获取合同生效时间
        geteffect() {
            let params = {
                policy_id: this.currentRow.policy_id
            };
            new Promise((resolve, reject) => {
                policyGetEffect(params)
                    .then(response => {
                        if (response.data.err == 0) {
                            if (response.data.data.effect_date) {
                                this.effect.effect_datetime =
                                    response.data.data.effect_date;
                                this.effect.effect_date =
                                    response.data.data.effect_date;
                            }
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        //获取承保时间
        getunderwrite() {
            let params = {
                policy_id: this.currentRow.policy_id
            };
            new Promise((resolve, reject) => {
                policyGetUnderwrite(params)
                    .then(response => {
                        if (response.data.err == 0) {
                            this.$refs["underwrite"].resetFields();
                            this.underwrite.underwrite_datetime = response.data
                                .data.underwrite_date
                                ? response.data.data.underwrite_date
                                : "";
                            this.underwrite.underwrite_date = response.data.data
                                .underwrite_date
                                ? response.data.data.underwrite_date
                                : "";
                            this.underwrite.policy_num = response.data.data
                                .policy_num
                                ? response.data.data.policy_num
                                : "";
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        showupload(index) {
            window.open(this.receiptform.receipt_document[index]);
        },
        toDetail(id) {
            this.$router.push({
                name: "underwrite_policy_update",
                params: {
                    id: id
                }
            });
        },
        toUpdate(id) {
            this.$router.push({
                name: "policy_update",
                params: {
                    id: id
                }
            });
        },
        //编辑保单
        policyEdit() {
            console.log(this.currentRow.policy_id);
            this.toUpdate(this.currentRow.policy_id);
        },
        //搜索保险公司change事件
        // comchange(value){
        //     this.cname = value.label
        // },
        // remoteCom(query){
        //     if (query !== '') {
        //         if(query == this.cname){
        //             this.searchForm.cid = ''
        //             return
        //         }
        //         this.proloading = true;
        //         this.remotecom(query)
        //     } else {
        //         this.remotecom('')
        //     }
        // },
        // remotecom:debounce(function (query) {
        //     new Promise((resolve, reject) => {
        //         let _params = {
        //             name:query
        //         }
        //         parteGetByName(_params).then(response => {
        //                 console.log(response.data)
        //                 if (response.data.err == 0) {
        //                     this.proloading = false;
        //                     const list = response.data.data.map(item => {
        //                     return {
        //                             value: item.cid,
        //                             label: item.name
        //                         };
        //                     });
        //                     this.comoptions = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);
        //                 } else {
        //                     this.$Message.error(response.data.info);
        //                 }
        //                 resolve();
        //             }).catch(error => {
        //                 reject(error);
        //             });
        //         });
        // },300),
        //远程请求业务员
        agentchange(value) {
            this.aname = value.label;
        },
        remoteemployee(query) {
            if (query !== "") {
                if (query == this.aname) {
                    this.searchForm.agent_name = "";
                    return;
                }
                this.proloading = true;
                this.remoteagent(query);
            } else {
                this.employeelist = [];
            }
        },
        remoteagent: debounce(function(query) {
            new Promise((resolve, reject) => {
                let _params = {
                    name: query
                };
                getByName(_params)
                    .then(response => {
                        console.log(response.data);
                        if (response.data.err == 0) {
                            // this.emplist = response.data.data
                            this.proloading = false;
                            const list = response.data.data.map(item => {
                                return {
                                    value: item.id,
                                    label: item.name
                                };
                            });
                            this.employeelist = list.filter(
                                item =>
                                    item.label
                                        .toLowerCase()
                                        .indexOf(query.toLowerCase()) > -1
                            );
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        }, 300),
        //设置回访时间
        policyVisitBtn() {
            this.getvisit();
            this.revisitModal = !this.revisitModal;
        },
        //设置回执时间
        policyReceiptBtn() {
            // this.receiptform.receipt_date="";
            // this.receiptform.receipt_datetime="";
            this.updatefilesname = [];
            this.getreceipt();
            this.receiptModal = !this.receiptModal;
        },
        //合同生效
        policyeffectBtn() {
            this.geteffect();
            this.effectModal = !this.effectModal;
        },
        //承保
        policyUnderwriteBtn() {
            this.getunderwrite(); //policyGetUnderwrite
            this.underwriteModal = !this.underwriteModal;
        },
        //时间转换
        datachange(date, obj, param) {
            obj[param] = date;
        },
        tableCurrentChange(currentRow, oldCurrentRow) {
            console.log(currentRow);
            console.log(oldCurrentRow);
            this.tableaction = false;
            this.currentRow = currentRow;
            console.log(this.currentRow);
        },
        // 搜索
        search() {
            this.page = 1;
            this.searchForm.p = 1;
            this.$refs["pages"].currentPage = 1;
            this.getList();
        },
        // 获取承保单列表
        getList() {
            this.tableloading = true;
            this.tableaction = true;
            new Promise((resolve, reject) => {
                policyGetList(this.searchForm)
                    .then(response => {
                        if (response.data.err == 0) {
                            this.policylist = response.data.data.list;
                            this.listTotal = response.data.data.total;
                            this.tableloading = false;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        // 页码改变
        pageChange(page) {
            this.page = page;
            this.searchForm.p = page;
            this.getList();
        },
        // 每页条数改变
        pageSizeChange(pagesize) {
            this.pagesize = pagesize;
            this.searchForm.pagesize = pagesize;
            this.getList();
        },
        del(param) {
            new Promise((resolve, reject) => {
                delPolicy(param)
                    .then(response => {
                        if (response.data.err == 0) {
                            this.getList();
                            this.$Message.success(response.data.info);
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    })
                    .catch(error => {
                        reject(error);
                    });
            });
        },
        //新增承保保单
        createPloicy() {
            this.$router.push({
                name: "policy_create"
            });
        },
        // 删除时弹出对话框
        policyDel() {
            this.$Modal.confirm({
                title: "提示",
                content: "是否要删除该保单?",
                onOk: () => {
                    let _params = {
                        policy_id: this.currentRow.policy_id
                    };
                    this.del(_params);
                }
            });
        },
        // 回访
        visitInsure() {
            //visitInsure
            this.$refs["revisit"].validate(valid => {
                if (valid) {
                    this.revisitInsure.policy_id = this.currentRow.policy_id;
                    new Promise((resolve, reject) => {
                        policyVisit(this.revisitInsure)
                            .then(response => {
                                if (response.data.err == 0) {
                                    this.getList();
                                    this.$Message.success(response.data.info);
                                    this.revisitModal = false;
                                    this.loading = true;
                                } else {
                                    this.$Message.error(response.data.info);
                                    setTimeout(() => {
                                        this.loading = false;
                                        this.$nextTick(() => {
                                            this.loading = true;
                                        });
                                    }, 2000);
                                }
                                resolve();
                            })
                            .catch(error => {
                                reject(error);
                            });
                    });
                } else {
                    setTimeout(() => {
                        this.loading = false;
                        this.$nextTick(() => {
                            this.loading = true;
                        });
                    }, 2000);
                }
            });
        },
        //回执
        receiptok() {
            this.$refs["receiptform"].validate(valid => {
                if (valid) {
                    this.receiptform.policy_id = this.currentRow.policy_id;
                    new Promise((resolve, reject) => {
                        policyReceipt(this.receiptform)
                            .then(response => {
                                if (response.data.err == 0) {
                                    this.getList();
                                    this.$Message.success(response.data.info);
                                    this.receiptModal = false;
                                    this.loading = true;
                                } else {
                                    let _this = this;
                                    this.$Message.error(response.data.info);
                                    setTimeout(() => {
                                        _this.loading = false;
                                        _this.$nextTick(() => {
                                            _this.loading = true;
                                        });
                                    }, 2000);
                                }
                                resolve();
                            })
                            .catch(error => {
                                reject(error);
                            });
                    });
                } else {
                    let _this = this;
                    setTimeout(() => {
                        _this.loading = false;
                        _this.$nextTick(() => {
                            _this.loading = true;
                        });
                    }, 2000);
                }
            });
        },
        //合同生效时间
        effectok() {
            this.$refs["effect"].validate(valid => {
                if (valid) {
                    this.effect.policy_id = this.currentRow.policy_id;
                    new Promise((resolve, reject) => {
                        policyEffect(this.effect)
                            .then(response => {
                                if (response.data.err == 0) {
                                    this.getList();
                                    this.$Message.success(response.data.info);
                                    this.effectModal = false;
                                    this.loading = true;
                                } else {
                                    this.$Message.error(response.data.info);
                                    setTimeout(() => {
                                        this.loading = false;
                                        this.$nextTick(() => {
                                            this.loading = true;
                                        });
                                    }, 2000);
                                }
                                resolve();
                            })
                            .catch(error => {
                                reject(error);
                            });
                    });
                } else {
                    setTimeout(() => {
                        this.loading = false;
                        this.$nextTick(() => {
                            this.loading = true;
                        });
                    }, 2000);
                }
            });
        },
        renewalInsureok() {},
        // 承保
        reInsure() {
            //underwrite
            this.$refs["underwrite"].validate(valid => {
                if (valid) {
                    this.underwrite.policy_id = this.currentRow.policy_id;
                    new Promise((resolve, reject) => {
                        policyUnderwrite(this.underwrite)
                            .then(response => {
                                if (response.data.err == 0) {
                                    this.getList();
                                    this.$Message.success(response.data.info);
                                    this.underwriteModal = false;
                                    this.loading = true;
                                } else {
                                    this.$Message.error(response.data.info);
                                    setTimeout(() => {
                                        this.loading = false;
                                        this.$nextTick(() => {
                                            this.loading = true;
                                        });
                                    }, 2000);
                                }
                                resolve();
                            })
                            .catch(error => {
                                reject(error);
                            });
                    });
                } else {
                    setTimeout(() => {
                        this.loading = false;
                        this.$nextTick(() => {
                            this.loading = true;
                        });
                    }, 2000);
                }
            });
        }
    }
};
</script>